package com.kky.pp.adapter

import android.app.Activity
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.kky.pp.R
import com.kky.pp.entity.MemberSubscribeEntity
import com.custom.base.base.BaseRecyclerAdapter
import com.custom.base.view.SuperViewHolder
import com.kky.pp.util.DensityUtil

class MemberSubscriptionAdapter(
    listModel: ArrayList<MemberSubscribeEntity.Data.Subscriptions>,
    activity: Activity,
    val itemBgResId :Int = 0
) : BaseRecyclerAdapter<MemberSubscribeEntity.Data.Subscriptions>(listModel, activity){
    override val layoutId: Int
        get() = R.layout.item_member_subscription

    override fun onBindItemHolder(position: Int, holder: SuperViewHolder, model: MemberSubscribeEntity.Data.Subscriptions, payloads: List<Any>?) {
        val itemLogo = holder.getView<ImageView>(R.id.imgViewItemBuyVipLogo)
        val itemTitle = holder.getView<TextView>(R.id.txtItemBuyVipTitles)
        val itemContent = holder.getView<TextView>(R.id.txtItemBuyVipContents)
        Glide.with(mActivity)
            .load(model.icon)
            .error(R.drawable.image_error)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(itemLogo)
        itemTitle.text=model.tip
        itemContent.text=model.content
        if (itemBgResId!=0){
            holder.itemView.setBackgroundResource(itemBgResId)
            (holder.itemView.layoutParams as RecyclerView.LayoutParams).setMargins(DensityUtil.dip2px(mActivity,12f),DensityUtil.dip2px(mActivity,5f),DensityUtil.dip2px(mActivity,12f),
                if (position == dataList.size-1) DensityUtil.dip2px(mActivity,5f) else 0)
        }
    }
}